package com.nefits.bean;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SCBean {
	private String deviceCode;
	private Date time;
	private String status;
	private int first_in;
	private int first_out;
	private int second_in;
	private int second_out;
	private int third_in;
	private int third_out;
	private int fourth_in;
	private int fourth_out;
	
	private DateFormat parseFrom = new SimpleDateFormat("yyyyMMddHHmm");
	private DateFormat parseTo = new SimpleDateFormat("yyyyMMdd HH:mm");
	
	public SCBean(){
		
	}
	public SCBean(String scContent) throws ParseException{
		if(scContent!=null && scContent.length()==54){
			this.deviceCode=scContent.substring(0, 8);
			this.time=parseFrom.parse(scContent.substring(8,20));
			this.status=scContent.charAt(21)=='g'?"\u6b63\u5e38":"\u65ad\u5f00"; //正常,断开
			this.first_in=Integer.parseInt(scContent.substring(22,26));
			this.first_out=Integer.parseInt(scContent.substring(26,30));
			this.second_in=Integer.parseInt(scContent.substring(30,34));
			this.second_out=Integer.parseInt(scContent.substring(34,38));
			this.third_in=Integer.parseInt(scContent.substring(38,42));
			this.third_out=Integer.parseInt(scContent.substring(42,46));
			this.fourth_in=Integer.parseInt(scContent.substring(46,50));
			this.fourth_out=Integer.parseInt(scContent.substring(50,54));
		}
	}
	public String toXmlString(){
		StringBuffer xml = null;
		if(this.deviceCode!=null && !"".equals(this.deviceCode)){
			xml = new StringBuffer();
			xml.append("\t<row>\n");
			xml.append("\t\t<deviceCode>").append(this.deviceCode).append("</deviceCode>\n");
			xml.append("\t\t<time>").append(parseTo.format(this.time)).append("</time>\n");
			xml.append("\t\t<status>").append(this.status).append("</status>\n");
			xml.append("\t\t<in>").append(this.first_in+this.second_in+this.third_in+this.fourth_in).append("</in>\n");
			xml.append("\t\t<out>").append(this.first_out+this.second_out+this.third_out+this.fourth_out).append("</out>\n");
			xml.append("\t</row>\n");
			return xml.toString();
		}
		return null;
	}
	public String getDeviceCode() {
		return deviceCode;
	}
	public void setDeviceCode(String deviceCode) {
		this.deviceCode = deviceCode;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public int getFirst_in() {
		return first_in;
	}
	public void setFirst_in(int first_in) {
		this.first_in = first_in;
	}
	public int getFirst_out() {
		return first_out;
	}
	public void setFirst_out(int first_out) {
		this.first_out = first_out;
	}
	public int getSecond_in() {
		return second_in;
	}
	public void setSecond_in(int second_in) {
		this.second_in = second_in;
	}
	public int getSecond_out() {
		return second_out;
	}
	public void setSecond_out(int second_out) {
		this.second_out = second_out;
	}
	public int getThird_in() {
		return third_in;
	}
	public void setThird_in(int third_in) {
		this.third_in = third_in;
	}
	public int getThird_out() {
		return third_out;
	}
	public void setThird_out(int third_out) {
		this.third_out = third_out;
	}
	public int getFourth_in() {
		return fourth_in;
	}
	public void setFourth_in(int fourth_in) {
		this.fourth_in = fourth_in;
	}
	public int getFourth_out() {
		return fourth_out;
	}
	public void setFourth_out(int fourth_out) {
		this.fourth_out = fourth_out;
	}
	
	
	
}
